#include <iostream>
#include <fstream>
#include <ctime>
#include <vector>
#include <string>
using namespace std;

int stringToInt(string str) {
	int res = 0;
	for (auto& i : str) res = res * 10 + ((int)i - 48);
	return res;
}

void BubbleSort(string file_name) {
	float t = clock();
	vector<int> arr;
	ifstream readFile(file_name);
	string line;

	if (readFile.is_open()) {
		while (std::getline(readFile, line)) {
			arr.push_back(stringToInt(line));
		}
	}

	for (int i = 0; i < (int)arr.size(); i++) {
		for (int j = 0; j < (int)arr.size() - 1; j++) {
			if (arr[j] > arr[j + 1]) {
				int temp = arr[j];
				arr[j] = arr[j + 1];
				arr[j + 1] = temp;
			}
		}
	}

	float t2 = clock();
	for (auto& i : arr) std::cout << i << ' ';
	std::cout << "\nTime sorted by: " << (t2 - t) / CLOCKS_PER_SEC << '\n';
	readFile.close();
}

int main() {
	std::cout << "Array 1\n";
	BubbleSort("m1_sorted.txt");
	std::cout << "\nArray 2\n";
	BubbleSort("m2_reverse.txt");
	std::cout << "\nArray 3\n";
	BubbleSort("m3_shuffle.txt");

	system("pause");
}